
$(document).ready(function() {
    $(document).on('click', ".fa-compress, .fa-expand", function() {
    var $p = $(this).closest(".panel, .view_div, .sql_textarea_parent");
		$p.toggleFullScreen();
		return false;
	});
}).keydown(function (e) {
     if (e.which === 27) {
        // 关闭全屏
      	$(".fa-expand").closest(".panel, .view_div, .sql_textarea_parent").toggleFullScreen();
     }
});;

$.prototype.toggleFullScreen = function() {
	var $this = this,p = $this.parent(), html = $("html")[0], frame = this[0];
	if (typeof $this[0] == 'undefined') {
	    return;
	}
	if (typeof $this.data('fullScreen') == 'undefined' || $this.data('fullScreen') == false) { // toogle on data
		$this.data('fullScreen', true);
		$this.addClass("full_screen");
		$this.attr('data-style', $this.attr("style"));
		$this.attr('data-html_style', $("html").attr("style"));
		$this.data('htm_scrollTop', html.scrollTop);
		$this.data('htm_scrollLeft', html.scrollLeft);
		
		html.style.overflow = "hidden";
		html.scrollTop = 0;
		html.scrollLeft = 0;

		$this.css("position", "absolute");
		$this.css("width", html.clientWidth + "px");
		$this.css("height", html.clientHeight + "px");
		$this.css("display", "block");
		$this.css("zIndex", "999999");
		$this.css("top", "0px");
		$this.css("left", "0px");
		$this.find(".fa-compress").eq(0).removeClass("fa-compress").addClass("fa-expand");
		$this.removeClass("fa-compress_parent").addClass("fa-expand_parent");
		
	} else { // toogle off data
		$this.data('fullScreen', false);
        $this.removeClass("full_screen");
		var attr=$this.attr("data-style");
		$this.attr("style", (attr) ? attr : "");
		attr=$this.attr("data-html_style");
		$("html").attr("style", (attr) ? attr : "");
		html.style.height = $this.data('html_height');
		html.style.overflow = $this.data('html_overflow');
		html.scrollTop = $this.data('htm_scrollTop');
		html.scrollLeft = $this.data('htm_scrollLeft');
		$this.find(".fa-expand").eq(0).removeClass("fa-expand").addClass("fa-compress");
		$this.removeClass("fa-expand_parent").addClass("fa-compress_parent");
	}
};